home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / obrn-a_1.5_src.lha / oberon-a / source3.lha / Source / Misc / HexConvert.mod < prev    next >
Encoding:
Text File  |  1995-01-26  |  2.1 KB  |  80 lines

  1. (*************************************************************************
  2.  
  3.      $RCSfile: HexConvert.mod $
  4.   Description: A little utility to convert unsigned hex integers to their
  5.                signed equivalents.
  6.  
  7.    Created by: fjc (Frank Copeland)
  8.     $Revision: 1.3 $
  9.       $Author: fjc $
  10.         $Date: 1995/01/26 01:05:15 $
  11.  
  12.   Log entries are at the end of the file.
  13.  
  14. *************************************************************************)
  15.  
  16. <*STANDARD-*>
  17.  
  18. MODULE HexConvert;
  19.  
  20. IMPORT IO := StdIO;
  21.  
  22. CONST
  23.   VersionTag = "$VER: HexConvert 1.1 (24.9.94)\r\n";
  24.   VersionStr = "HexConvert 1.1 (24.9.94)\r\n";
  25.   CopyrightStr = "Written by Frank Copeland\n";
  26.  
  27. VAR
  28.   i, j, k : INTEGER; temp : LONGINT; ch : CHAR; digit : ARRAY 17 OF CHAR;
  29.  
  30. BEGIN (* HexConvert *)
  31.   IO.WriteStr (VersionStr);
  32.   IO.WriteStr (CopyrightStr);
  33.   IO.WriteLn ();
  34.   digit := "0123456789ABCDEF";
  35.   LOOP
  36.     i := 0; temp := 0;
  37.     IO.WriteStr ("Enter a hex integer => ");
  38.     LOOP
  39.       IO.Read (ch); IF ch = "\n" THEN EXIT END;
  40.       ch := CAP (ch); INC (i);
  41.       IF (ch >= "0") & (ch <= "9") THEN
  42.         k := ORD (ch) - ORD ("0")
  43.       ELSIF (ch >= "A") & (ch <= "F") THEN
  44.         k := ORD (ch) - (ORD ("A") - 10)
  45.       ELSE
  46.         IO.WriteStr ("\n !! Illegal hex digit\n"); temp := -1; EXIT
  47.       END;
  48.       IF i < 5 THEN temp := temp * 16 + k END
  49.     END;
  50.     IF i = 0 THEN
  51.       EXIT
  52.     ELSIF i > 4 THEN
  53.       IO.WriteStr ("\n !! Number is too big\n"); temp := -1
  54.     END;
  55.     IF temp >= 0 THEN
  56.       IF temp > 32767 THEN DEC (temp, 65536) END;
  57.       IO.WriteStr (" >> Signed equivalent : ");
  58.       IF temp < 0 THEN IO.Write ("-"); temp := ABS (temp) END;
  59.       IO.WriteHex (temp); IO.WriteLn ()
  60.     END;
  61.   END;
  62.   IO.WriteStr ("\nAll finished\n");
  63. END HexConvert.
  64.  
  65. (*************************************************************************
  66.  
  67.   $Log: HexConvert.mod $
  68. # Revision 1.3  1995/01/26  01:05:15  fjc
  69. # - Release 1.5
  70. #
  71. # Revision 1.2  1994/09/25  18:25:17  fjc
  72. # - Uses new syntax for external code declarations
  73. #
  74. # Revision 1.1  1994/06/09  14:29:51  fjc
  75. # Initial revision
  76. #
  77. *************************************************************************)
  78.  
  79.  
  80.